<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/17
 * Time: 9:14
 */
//打印函数
function p($arr){
    echo "<pre/>".print_r($arr,true)."<pre/>";
}

//配置项函数
function C($name=null,$value=null){
    static $config = [];
    if(is_null($name)){
        return $config;
    }elseif(is_array($name)){
       return $config = array_merge($config,$name);
    }elseif(is_null($value)){
        //获取值
        return isset($config[$name])?$config[$name]:null;
    }else{
        //赋值
        return $config[$name] = $value;
    }
}

function M($model){
    return new Model($model);
}

function K($model){
    $model = ucfirst($model).'Model';
    return new $model();
}

//中断脚本执行
function halt($msg){
    header('Content-type:text/html;charset=utf-8;');
    echo $msg;
    exit;
}

//类文件自动加载
function __autoload($class){
    if(substr($class,-10) == 'Controller'){
        require_array([
            //在控制器目录和框架目录分别去搜寻需要的类文件
            CONTROLLER_PATH.$class.'.class.php',
            V5_PATH.$class.'.class.php'
        ]);
    }elseif(substr($class,-5) == 'Model'){
        require_array([
            MODEL_PATH.$class.'.class.php',
            V5_PATH.$class.'.class.php'
        ]);
    }elseif(substr($class,0,2) == 'Db'){
        require_array([
            V5_PATH.'Driver/Db/'.$class.'.class.php'
        ]);
    }
}

//以数组形式加载文件
function require_array($files){
    foreach($files as $file){
        is_file($file) && require($file);
    }
}